<!--
 * @Description: 大事记-时间轴
-->

<template>
  <div>
    <!-- 大事记时间轴： 横向-->
    <div :style="style" class="memorabilia-horizental" v-if="!direction">
      <div :style="`width:${memorabiliaDetailWidth}px`" class="memorabilia-detail">
        <div class="memorabilia-hor-item" v-for="(item, index) in newLineData" :key="index">
          <div :style="backgroundColor" class="item-line"> </div>
          <div class="item-detail">
            <div class="item-time">
              <span :title="item.eventTitle" :style="fontColor">
                {{ item.eventTitle }}
              </span>
            </div>
            <div class="item-dot" :style="itemDot"></div>
            <div class="item-content" style="white-space: normal">
              <a
                v-if="item.eventLink"
                :title="item.eventThings"
                :href="item.eventLink"
                target="_blank"
              >
                {{ item.eventThings }}
              </a>
              <span v-else :title="item.eventThings">{{ item.eventThings }}</span>
            </div>
          </div>
        </div>
        <span class="vportal vp-Flag" :style="fontColor" v-if="newLineData.length"></span>
      </div>
    </div>

    <!-- 大事记时间轴： 纵向-->
    <div :style="style" class="memorabilia-vertical-year" v-if="direction">
      <div class="memorabilia-vertical-year-contentDetail">
        <div class="first-item">
          <span class="vportal vp-Flag" :style="fontColor" v-if="newLineData.length"></span>
          <div class="first-item-detail">
            <div class="year-time" :sytle="fontColor">
              <span :title="firstItem.eventTitle" :style="fontColor">{{
                firstItem.eventTitle
              }}</span>
            </div>
            <div class="year-detail"
              ><a
                v-if="firstItem.eventLink"
                :title="firstItem.eventThings"
                :href="firstItem.eventLink"
                target="_blank"
                >{{ firstItem.eventThings }}</a
              >
              <span v-else :title="firstItem.eventThings">{{ firstItem.eventThings }}</span>
            </div>
          </div>
        </div>
        <div class="memorabilia-vertical-year-detail" :style="memorabiliaVerticalYearDetail">
          <div class="node" :style="backgroundColor"></div>
          <div
            class="memorabilia-vertical-year-item"
            v-for="(item, index) in otherItem"
            :key="index"
          >
            <div class="year-bubble">
              <span class="year-bubble-bg" :style="backgroundColor"></span>
              <span class="vportal vp-online1" :style="fontColor"></span>
            </div>
            <div class="year-content">
              <div class="year-time" :style="fontColor">
                <span :title="item.eventTitle" :style="fontColor">{{ item.eventTitle }}</span>
              </div>
              <div class="year-detail">
                <a
                  v-if="item.eventLink"
                  :title="item.eventThings"
                  :href="item.eventLink"
                  target="_blank"
                  >{{ item.eventThings }}</a
                >
                <span v-else :title="item.eventThings">{{ item.eventThings }}</span></div
              >
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  // import SpaceNav from '../space-nav';
  import { methods } from '@/utils';
  const ITEM_WIDTH = 150; //每一项宽度
  export default {
    name: 'TimeLine',
    // components: { SpaceNav },
    props: {
      sectionData: {
        type: Object,
        // default: () => {
        //     return {
        //         options: {
        //             direction: true,
        //             space: 150
        //         },
        //         data: {}
        //     }
        // }
      },
      contentWidth: { type: Number },
    },

    data() {
      return {
        style: {},
        memorabiliaDetailWidth: 0, //横向宽度
      };
    },

    computed: {
      itemDot() {
        return {
          border: '5px solid ' + this.sectionData.options.fontColor,
        };
      },

      direction() {
        return this.sectionData.data.style == '1' && true;
      },

      size() {
        return this.direction == '1'
          ? 'height:' + `${methods.getContentHeight(this.sectionData.options)}px`
          : 'width: 150px';
      },

      newLineData() {
        return this.sectionData.data.o;
      },

      // 纵向
      firstItem() {
        return this.sectionData.data.o.length > 0 ? this.sectionData.data.o[0] : {};
      },

      otherItem() {
        return this.sectionData.data.o.length > 0
          ? this.sectionData.data.o.slice(1, this.sectionData.data.o.length)
          : [];
      },

      memorabiliaVerticalYearDetail() {
        return {
          borderLeft: '1px dashed ' + this.sectionData.options.fontColor,
        };
      },

      fontColor() {
        return {
          color: this.sectionData.options.fontColor,
        };
      },
      backgroundColor() {
        return {
          backgroundColor: this.sectionData.options.fontColor,
        };
      },
    },
    created() {
      this.style = {
        height: `${methods.getContentHeight(this.sectionData.options)}px`,
        backgroundColor: `${this.sectionData.options.backgroundColor}`,
      };
      //横向的设置宽度
      if (!this.direction) {
        this.memorabiliaDetailWidth = this.newLineData.length * ITEM_WIDTH + 22;
      }
    },
  };
</script>

<style lang="scss" scoped>
  * {
    box-sizing: border-box;
  }

  //#time-line {
  //    width: 100%;
  //    height: 100%;
  //    border-radius: 5px;
  //    background-color: #fff;
  //    margin-top: 10px;
  //}
  //
  //.big-thing {
  //    width: 100%;
  //    height: 40px;
  //    line-height: 40px;
  //    padding-left: 10px;
  //    border-bottom: 1px solid #ddd;
  //}
  //
  //.time-item {
  //    position: relative;
  //    font-size: 14px;
  //    color: #333;
  //
  //    .time-icon {
  //        position: absolute;
  //        width: 24px;
  //        height: 24px;
  //    }
  //}
  //
  //.time {
  //    color: #2490f8;
  //    font-size: 18px;
  //}
  //
  //.line-column {
  //    margin-left: 30px;
  //    padding-top: 30px;
  //}
  //
  //.line-row {
  //    // margin-left: 30px;
  //    // display: flex;
  //    padding-top: 50px !important;
  //}
  //
  //.time-item-column {
  //    border-left: 1px solid #324fde;
  //
  //    .time-icon {
  //        top: -12px;
  //        left: -12px;
  //    }
  //
  //    .content {
  //        position: absolute;
  //        height: 80px;
  //        left: 20px;
  //        top: -12px;
  //    }
  //}
  //
  //.time-item-row {
  //    position: relative;
  //    //border-top: 1px solid #324fde;
  //
  //    height: 170px;
  //    width: 150px;
  //    float: left;
  //
  //    .time-icon {
  //        top: -12px;
  //        left: 50%;
  //        margin-left: -12px;
  //    }
  //
  //    .content {
  //        width: 100%;
  //        height: 100%;
  //        padding-top: 15px;
  //        text-align: center;
  //
  //        .time {
  //            width: 100px;
  //            text-align: center;
  //            position: absolute;
  //            top: -40px;
  //            left: 50%;
  //            margin-left: -50px;
  //        }
  //    }
  //}
  //
  //.time-item-column.last-item {
  //    height: 50px !important;
  //}
  //
  //.time-item-row.side-item {
  //    //width: 100px !important;
  //}

  .memorabilia-horizental {
    width: 100%;
    padding: 0 15px;
    overflow: auto;

    .vportal {
      position: relative;
      display: inline-block;
      margin-top: 40px;
      font-size: 22px;
      vertical-align: top;
    }

    .memorabilia-detail {
      padding: 10px 0;
      // height: 100%;
      margin: 0 auto;
      // width: 1225px;
      overflow: hidden;
      // overflow-x: auto;
      // overflow-y: hidden;
      // white-space: nowrap;

      .memorabilia-hor-item {
        position: relative;
        float: left;
        width: 150px;
        // height: 170px;
        // overflow: hidden;

        .item-line {
          position: absolute;
          top: 49px;
          left: 0;
          z-index: 10;
          width: 100%;
          height: 2px;
          background-color: #fdab2c;
        }

        .item-detail {
          // position: absolute;
          // top: 0;
          // right: 0;
          // bottom: 0;
          // left: 0;
          z-index: 11;
          padding: 0 25px;

          .item-time {
            width: 100%;
            height: 26px;
            margin-top: 0;
            overflow: hidden;
            font-size: 16px;
            color: #fdab2c;
            text-align: center;
            text-overflow: ellipsis;
            white-space: nowrap;
          }

          .item-dot {
            width: 15px;
            height: 15px;
            margin: 0 auto;
            margin-top: 15px;
            background-color: #fff;
            border: 5px solid #fdab2c;
            border-radius: 100%;
          }

          .item-content {
            position: relative;
            width: 100%;
            // max-height: 80px;
            margin-top: 10px;
            font-size: 12px;
            line-height: 20px;
            color: #333;
            text-align: center;
            word-break: break-all;
            white-space: normal;

            a:hover {
              color: #2490f8;
            }
          }
        }
      }
    }
  }

  .memorabilia-vertical-year {
    position: relative;
    overflow-y: auto;

    .vportal {
      position: absolute;
      left: -7px;
      font-size: 22px;
      color: #f5b64a;
    }

    .memorabilia-vertical-year-contentDetail {
      position: absolute;
      right: 10px;
      left: 20px;
      padding-top: 5px;

      .first-item {
        position: absolute;
        width: 100%;

        .first-item-detail {
          position: absolute;
          right: 25px;
          left: 25px;

          .year-time {
            overflow: hidden;
            font-size: 16px;
            color: #f5b64a;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
      }

      .memorabilia-vertical-year-detail {
        position: relative;
        padding-top: 15px;
        padding-bottom: 10px;
        margin-top: 38px;
        border-left: 1px dashed #f5b64a;
        box-sizing: border-box;

        .node {
          position: absolute;
          top: -11px;
          left: -2px;
          width: 4px;
          height: 4px;
          background: #f5b64a;
          border-radius: 100%;
        }

        .memorabilia-vertical-year-item {
          position: relative;
          height: 40px;
          padding-left: 25px;
          margin: 15px 0;

          .year-bubble {
            position: absolute;
            top: 0;
            left: -12px;
            z-index: 10;
            width: 25px;
            height: 25px;
            font-size: 14px;
            line-height: 25px;
            color: #f5b64a;
            text-align: center;
            border-radius: 100%;

            .year-bubble-bg {
              position: absolute;
              top: 0;
              left: 0;
              width: 100%;
              height: 100%;
              border-radius: 100%;
              opacity: 0.3;
              filter: alpha(opacity=30);
            }

            .vportal {
              position: relative;
              left: auto;
              font-size: 14px;
            }
          }
        }
      }
    }
  }

  .year-detail {
    overflow: hidden;
    font-size: 14px;
    color: #333;
    text-overflow: ellipsis;
    white-space: nowrap;

    a:hover {
      color: #2490f8;
    }
  }
</style>
